package com.vcs.frm.web.common;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.vcs.frm.domain.Job;
import com.vcs.frm.service.common.CommonService;

@Controller
@RequestMapping(value = "/")
public class JobController {

	private final Logger log = Logger.getLogger(this.getClass());
	
	@Autowired
	private CommonService commonService;
	
	public void setCommonService(CommonService commonService) {
		this.commonService = commonService;
	}
	
	/**
	 * This method renders a job.
	 * @param jobId
	 * @return
	 */
	@RequestMapping(value = "/jobs/{jobId}")
	public ModelAndView getJobByJobId(@PathVariable("jobId") Long jobId){
		log.info("method - getJobByJobId - "+ jobId);
		
		ModelAndView mav = new ModelAndView();
		Job job = commonService.getJobByJobId(jobId);
		
		mav.addObject("job", job);
		mav.setViewName("renderJob");
		return mav;
	}
}
